.PHONY: build_x64 build_aarch64 rebuild_x64 rebuild_aarch64 run burn clean clean_cross install_lib sync_sysroot
ORANGEPI_IP = 192.168.1.9

build_x64: 
	@mkdir -p build_x64
	@cd build_x64 && cmake .. && cmake --build . -- -j$(nproc)

# 交叉编译
build_aarch64:
	@mkdir -p build_aarch64
	@cd build_aarch64 && cmake -DCMAKE_TOOLCHAIN_FILE=./aarch64-toolchain.cmake .. && cmake --build . -- -j$(nproc)

rebuild_x64: clean build_x64

rebuild_aarch64: clean build_aarch64

clean:
	@rm -rf ./build/* ./build_aarch64/*

burn:
# @scp -r /home/cwb/code/orangepi3b/project/build_aarch64/src/opencv_test/opencv_test orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project
# @scp -r /home/cwb/code/orangepi3b/project/build_aarch64/src/qt_test/qt_test orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project
# @scp -r /home/cwb/code/orangepi3b/project/build_aarch64/src/rknpu2_rga_pyh_test/rknpu2_rga_pyh_test orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project
	@scp -r /home/cwb/code/orangepi3b/project/build_aarch64/src/defect_dectect_system/defect_dectect_system orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project

install_lib:
	@rsync -av --links /home/cwb/code/orangepi3b/project/3rdparty/opencv-4.5.4/lib/* orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project/lib/
	@rsync -av --links /home/cwb/code/orangepi3b/project/3rdparty/qt-5.15.3/lib/*.so* orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project/lib/
	@rsync -av --links /home/cwb/code/orangepi3b/project/3rdparty/qt-5.15.3/plugins orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project/lib/
	@rsync -av --links /home/cwb/code/orangepi3b/project/3rdparty/liballocator/lib/* orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project/lib/
	@rsync -av --links /home/cwb/code/orangepi3b/project/3rdparty/rk_mpi_mmz/lib/* orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project/lib/
	@rsync -av --links /home/cwb/code/orangepi3b/project/3rdparty/rknpu2/lib/* orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project/lib/
	@rsync -av --links /home/cwb/code/orangepi3b/project/3rdparty/hikvision/lib/* orangepi@$(ORANGEPI_IP):/home/orangepi/ir_project/lib/

# 同步sysroot目录
sync_sysroot:
	@mkdir -p 3rdparty/sysroot/lib
	@mkdir -p 3rdparty/sysroot/usr
	@rsync -avz --rsync-path="sudo rsync" --delete orangepi@$(ORANGEPI_IP):/usr/lib 3rdparty/sysroot/usr/
	@rsync -avz --rsync-path="sudo rsync" --delete orangepi@$(ORANGEPI_IP):/usr/include 3rdparty/sysroot/usr/
	@rsync -avz --rsync-path="sudo rsync" --delete orangepi@$(ORANGEPI_IP):/lib 3rdparty/sysroot/
	@echo "修复软链接..."
	@symlinks -rc 3rdparty/sysroot
	@cd 3rdparty/sysroot/lib/aarch64-linux-gnu/ && rm libm.so && ln -sf libm.so.6 libm.so